<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="../../layui/css/layui.css" />
    <style>
        .layui-input {
            width: 220px;
        }
        .layui-form-item{
            margin-top: 5px;
            padding-bottom: 15px;
        }
    </style>
</head>
<body>
<form class="layui-form" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">活动主题</label>
        <div class="layui-input-block">
            <input type="text" name="asubject" required  lay-verify="required" placeholder="请输入活动主题" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">活动内容</label>
        <div class="layui-input-block">
            <input type="text" name="acontent" required  lay-verify="required" placeholder="请输入活动内容" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">活动地址</label>
        <div class="layui-input-block">
            <input type="text" name="asite" required  lay-verify="required" placeholder="请输入活动地址" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">活动花费</label>
        <div class="layui-input-block">
            <input type="text" name="acost" required  lay-verify="required" placeholder="请输入活动花费" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">组织者</label>
        <div class="layui-input-block">
            <input type="text" name="aorganizer" required  lay-verify="required" placeholder="请输入活动花费" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">举行时间</label>
        <div class="layui-input-block">
            <input name="ataketime" type="text" class="layui-input" id="test1">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button id="btn1" class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

<script src="../../layui/layui.js"></script>
<script>
    //Demo
    layui.use(['form','laydate'], function(){
        var form = layui.form;
        var laydate = layui.laydate;
        var $=layui.$;
        //监听提交
        form.on('submit(formDemo)', function(data){
            //通过ajax提交后台
            $.ajax({
                type:"post",
                url:"/ActivityServlet?method=insert",
                data:$('form').serialize(),
                //提交成功获取返回的数据
                dataType:'text',
                success:function(data){
                    if(data.code==0) {
                        layer.msg('新增成功')
                    }
                },
                error:function () {
                    layer.msg('新增失败')
                }
            })
            var index=parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
        });
        laydate.render({
            elem: '#test1'    //指定元素test1
        });
    });
</script>
</body>
</html>